home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / answers / comp / unix-faq / shell / zsh < prev   
Text File  |  1994-03-23  |  38KB  |  813 lines

  1. Newsgroups: comp.unix.shell,comp.answers,news.answers
  2. Path: bloom-beacon.mit.edu!hookup!swrinde!cs.utexas.edu!howland.reston.ans.net!EU.net!uknet!liv!amtp!pws
  3. From: pws@s-a.amtp.liv.ac.uk (Peter Stephenson)
  4. Subject: Z-shell Frequently-Asked Questions
  5. Message-ID: <PWS.94Mar23182651@suna.amtp.liv.ac.uk>
  6. Followup-To: comp.unix.shell
  7. Summary: Q's and A's about zsh, a powerful (and free) UNIX shell
  8. Sender: news@liverpool.ac.uk (News System)
  9. Supersedes: <PWS.94Feb28172214@suna.amtp.liv.ac.uk>    
  10. Nntp-Posting-Host: suna.amtp.liv.ac.uk
  11. Reply-To: Peter Stephenson <pws@s-a.amtp.liv.ac.uk>
  12. Organization: DAMTP, University of Liverpool
  13. Date: Wed, 23 Mar 1994 18:26:51 GMT
  14. Approved: news-answers-request@MIT.Edu
  15. Expires: Sun, 24 Apr 1994 00:00:00 GMT
  16. Lines: 794
  17. Xref: bloom-beacon.mit.edu comp.unix.shell:9130 comp.answers:4307 news.answers:16784
  18.  
  19. Archive-Name: unix-faq/shell/zsh
  20. Last-Modified: 1994/1/25
  21. Submitted-By: pws@s-a.amtp.liv.ac.uk (Peter Stephenson)
  22. Version: $Id: zsh.FAQ,v 1.23 1994/03/23 18:18:21 pws Exp pws $
  23. Frequency: Monthly
  24.  
  25. This document contains a list of frequently-asked (or otherwise
  26. significant) questions concerning the Z-shell, a command interpreter for
  27. many UNIX systems which is freely available to anyone with FTP access.
  28. Zsh is more powerful than every other common shell (sh, ksh, csh, tcsh
  29. and bash) put together.
  30.  
  31. Information on zsh is now available via the World Wide Web at
  32. http://crdmac11.colorado.edu:/zsh/zsh_home.html including this FAQ and
  33. much else (thanks to Mark Borges for this).
  34.  
  35. If you have never heard of `sh', `csh' or `ksh', then you are probably
  36. better off to start by reading a general introduction to UNIX rather
  37. than this document.
  38.  
  39. Another useful source of information is the collection of FAQ articles
  40. posted frequently to the Usenet news groups comp.unix.questions,
  41. comp.unix.shells and comp.answers with answers to general questions
  42. about UNIX.  The fifth of the seven articles deals with shells,
  43. including zsh, with a brief description of differences.  (This article
  44. also talks about shell startup files which would otherwise rate a
  45. mention here.)
  46.  
  47. If you just want to know how to get your hands on the latest version,
  48. skip to question 4); if you want to know what to do with insoluble
  49. problems, go to 22).
  50.  
  51. To encourage you to read on, if you don't know about zsh but are
  52. familiar with other UNIX shells, here are some things that zsh is
  53. particularly good at.  No claim of exclusivity is made, especially as
  54. shells copy one another, though in the areas of command line editing and
  55. globbing zsh is well ahead of the competition.  I am not aware of a
  56. major feature in any other freely-available shell which zsh does not
  57. also have.
  58.   Command line editing:
  59.     programmable completion: incorporates the ability to use
  60.       the full power of zsh globbing (compctl -g),
  61.     multi-line commands editable as a single buffer (even files!),
  62.     variable editing (vared),
  63.     command buffer stack,
  64.     print text straight into the buffer for immediate editing (print -z),
  65.     execution of unbound commands,
  66.     menu completion,
  67.     variable, editing function and option name completion,
  68.     inline expansion of variables, history commands.
  69.   Globbing --- extremely powerful, including:
  70.     recursive globbing (cf. find),
  71.     file attribute qualifiers (size, type, etc. also cf. find),
  72.     full alternation and negation of patterns.
  73.   Handling of multiple redirections (simpler than tee).
  74.   Large number of options for tailoring.
  75.   Path expansion (=foo -> /usr/bin/foo).
  76.   Adaptable messages for spelling, watch, time as well as prompt
  77.     (now including conditional expressions).
  78.   Named directories.
  79.   Comprehensive integer arithmetic.
  80.   Manipulation of arrays (including reverse subscripting).
  81.   Spelling correction.
  82.  
  83.  
  84. Notation: Quotes `like this' are ordinary textual quotation
  85. marks.  Other uses of quotation marks are input to the shell.
  86.  
  87. Contents:
  88. 1) What is it?
  89. 2) On what machines will it run?
  90. 3) What's the latest version?
  91. 4) Where do I get it?
  92. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  93. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  94. 7) How do I turn off spelling correction for an individual command?
  95. 8) How do I get the meta key to work on my xterm?
  96. 9) Why does my terminal act funny in way x?
  97. 10) Why does `$var' where var="foo bar" not do what I expect?
  98. 11) My PATH, (MANPATH, ...) sometimes doesn't handle tildes.  What gives?
  99. 12) How does base arithmetic work?
  100. 13) How do I get a newline in my prompt?
  101. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  102. 15) How do I execute command `foo' within function `foo'?
  103. 16) Why can't I get zsh to work with SGI's `userenv'?
  104. 17) Why do history substitutions with single bangs do something funny?
  105. 18) Why does zsh kill off all my background jobs when I logout?
  106. 19) I don't have root access: how do I make zsh my login shell?
  107. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  108. 21) What bugs are currently known and unfixed?
  109. 22) Where do I report bugs, get more info / who's working on zsh?
  110. 23) What's on the wish-list?
  111. --- End of Contents ---
  112.  
  113.  
  114. 1) What is it?
  115.  
  116.   Zsh is a UNIX command interpreter (shell) which of the standard shells
  117.   most resembles the Korn shell (ksh), although it is not completely
  118.   compatible.  It includes enhancements of many types, notably in the
  119.   command-line editor, options for customising its behaviour, filename
  120.   globbing, features to make C-shell (csh) users feel more at home and
  121.   extra features drawn from tcsh (another `custom' shell).
  122.  
  123.   It was written by Paul Falstad <pf@z-code.com> when a student at
  124.   Princeton; however, Paul doesn't maintain it any more and enquiries
  125.   should be sent to the mailing list (see question 22).  It is freely
  126.   available to anyone under unrestrictive conditions.
  127.  
  128.   For more information, the files doc/intro.txt or doc/intro.troff
  129.   included with the source distribution are highly recommended.  A list
  130.   of features is given in FEATURES, also with the source.
  131.  
  132.  
  133. 2) On what machines will it run?
  134.  
  135.   Zsh was written for machines of the Berkeley UNIX family; most such
  136.   machines (and all the most popular) will run it without major surgery.
  137.   Modifications have been made so that it should work under SYSVR4-based
  138.   operating systems such as Solaris 2.x and OSF/1.  This best thing is
  139.   to suck it and see.  You may not have to change too much: if you do
  140.   change anything, arrange for the shell script `buildzsh' to set the
  141.   necessary #define's, etc., without human intervention.  Recent
  142.   additions include Convex, Unicos and Linux support; there is a project
  143.   to allow POSIX.1 compilation (but note that that zsh is not itself
  144.   particularly POSIX-compliant at the moment).  Success has been
  145.   obtained on older SYSVR3 systems, but you may need to modify the code.
  146.   
  147.   If you add support for a new machine, it would be appreciated if you
  148.   could alter buildzsh to configure zsh automatically and send the
  149.   required context diffs to the list (see question 22).
  150.  
  151.  
  152. 3) What's the latest version?
  153.   
  154.   The latest production version is 2.3.1.  The current beta version is
  155.   2.4.  New patches occur frequently and are added to the archive (next
  156.   question).  At the time of writing the latest patch level was 309.
  157.   Note that this `open' development system does mean bugs are sometimes
  158.   introduced into the most recent archived version.  These are usually
  159.   fixed quickly.
  160.  
  161.   The next production version will be 2.5 (2.4 will not be released, so
  162.   as to minimise confusion over version numbers).  It is expected that
  163.   no new features will be added before the release.
  164.  
  165.  
  166. 4) Where do I get it?
  167.  
  168.   Bas de Bakker (bas@phys.uva.nl) is in charge of the archive and the
  169.   latest version is available for users east of the Atlantic from:
  170.     carlo.phys.uva.nl(145.18.218.21):/pub/bas/zsh/zsh-2.4beta.tar.gz
  171.   The latest full release is in zsh-2.3.1.tar.gz in the same directory.
  172.   Note that this is in gzip format: you will need GNU gzip from your
  173.   nearest GNU archive to unpack it.  There is also a version under RCS
  174.   control which may be more suitable for source hackers.
  175.  
  176.   Rick Ohnemus has a reflector site in the USA:
  177.         ftp.sterling.com (192.124.9.1):/zsh
  178.  
  179.   The 2.3.1 distribution is also available from ftp.uu.net and mirrors
  180.   in the directory pub/shells/zsh.
  181.  
  182.  
  183. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  184.  
  185.   As has already been mentioned, zsh is most similar to ksh, while many
  186.   of the additions are to please csh users.
  187.  
  188.   i) ksh:
  189.  
  190.   Most features of ksh (and hence also of sh) are implemented in zsh;
  191.   problems can arise because the implementation is slightly different.
  192.   Note also that not all ksh's are the same either.  I have based this
  193.   on the 11/16/88f version of ksh.
  194.  
  195.   Various options can be turned on which will increase ksh
  196.   compatibility, though decrease zsh's abilities: see the manual entries
  197.   for IGNORE_BRACES (though brace expansion occurs in some versions of
  198.   ksh), KSH_OPTION_PRINT, NO_BANG_HIST, NO_EQUALS, NO_HUP, NO_RCS,
  199.   NO_SHORT_LOOPS, PROMPT_SUBST, RM_STAR_SILENT, SH_WORD_SPLIT (see
  200.   question 10) and SINGLE_LINE_ZLE.  Note that you can also disable any
  201.   built-in commands which get in your way.  If invoked as `ksh', the
  202.   shell will try and set suitable options.
  203.  
  204.   Here are some differences from ksh which might prove significant for
  205.   ksh programmers, some of which may be interpreted as bugs; there must
  206.   be more.  Note that this list is deliberately rather full and that
  207.   most of the items are fairly minor.  Those marked `*' perform in a
  208.   ksh-like manner if the shell is invoked as ksh.
  209.   
  210.   Syntax:
  211.   * Shell word splitting: see question 10).  (This is particularly
  212.       frequently asked about.)
  213.     Arrays are more csh-like than ksh-like:
  214.       subscripts start at 1, not 0; array[0] refers to array[1];
  215.       `$array' refers to the whole array, not $array[0];
  216.       braces are unnecessary: $a[1] == ${a[1]}, etc.
  217.     Coprocesses are established by `coproc'; `|&' behaves like csh.
  218.   Command line substitutions, globbing etc.:
  219.     The results of parameter substitutions are treated as plain text:
  220.       `foo="*"; print $foo' prints all files in ksh but * in zsh.
  221.     The $((...)) version of numeric evaluation is not implemented; use $[...].
  222.     Treatment of backslashes within backquotes is different.
  223.     $PSn do not do parameter substitution by default (use promptsubst option).
  224.     Globbing does not allow ksh-style `pattern-lists'.  Equivalents:
  225.       -------------------------------------------------------------------
  226.              ksh             zsh          Meaning
  227.             -----           -----        ---------
  228.            !(foo)            ^foo        Anything but foo.
  229.                       or   foo1~foo2     Anything matching foo1 but foo2.
  230.       @(foo1|foo2|...)  (foo1|foo2|...)  One of foo1 or foo2 or ...
  231.            ?(foo)           (foo|)       Zero or one occurrences of foo.
  232.            *(foo)           (foo)#       Zero or more occurrences of foo.
  233.            +(foo)         foo(foo)#      One or more occurrences of foo.
  234.       -------------------------------------------------------------------
  235.       The last two (with `#') require the EXTENDED_GLOB option.
  236.     Unquoted assignments do file expansion after ':'s (intended for PATHs).
  237.     `integer' does not allow -i; integers in bases other than 10 do not
  238.       have "base#" prefixed to them when printed.
  239.   Command execution:
  240.     There is no ENV variable (use /etc/zshrc, ~/.zshrc; note also ZDOTDIR).
  241.     The PATH is not searched for commands specified at invocation without -c.
  242.   Aliases and functions:
  243.     The order in which aliases and functions are defined is significant
  244.       (function definitions with () expand aliases -- see question 6).
  245.     Aliases and functions cannot be exported.
  246.     There are no tracked aliases: command hashing replaces these.
  247.     The use of aliases for key bindings is replaced by `bindkey'.
  248.   Traps and signals:
  249.     By default, background jobs are killed when you log out:  see 18).
  250.     Traps and options are not local to functions; traps are not reset
  251.       automatically when called; traps are called as functions themselves
  252.       (this is a bug for the `trap "..." NAL' form of trap setting).
  253.     TRAPERR has become TRAPZERR (this was forced by UNICOS which has SIGERR).
  254.   Editing:
  255.     The options emacs, gmacs, privileged, trackall, viraw are not supported.
  256.       Use bindkey to change the editing behaviour: `set -o {emacs,vi}' 
  257.       become `bindkey -{e,v}'; for gmacs, go to emacs mode and use
  258.       `bindkey \^t gosmacs-transpose-characters'.  `Trackall' is replaced
  259.       by `hashcmds'.
  260.     The `keyword' option does not exist and -k is instead interactivecomments.
  261.       (`keyword' will not be in the next ksh release either.)
  262.     Management of histories in multiple shells is different:
  263.       the history list is not saved and restored after each command.
  264.     \ does not escape editing chars (use ^V).
  265.     Not all ksh bindings are set (e.g. `<ESC>#'; try <ESC>q).
  266.   * # in an interactive shell is not treated as a comment by default.
  267.   Built-in commands:
  268.     Some built-ins (r, autoload, history, integer ...) were aliases in ksh.
  269.     There is no built-in command newgrp: use a shell function, e.g.
  270.       newgrp () { ((SHLVL--)) ; exec command newgrp $* }
  271.       (in 2.4 you can get away with `alias newgrp="exec newgrp"'
  272.     `jobs' has no `-n' flag.
  273.     `read' has no `-s' flag.
  274.     In `let "i = foo"', foo is evaluated as a number, not an expression
  275.       (although in `let "i = $foo"' it is treated as an expression).
  276.   Other idiosyncrasies:
  277.     `select' always redisplays the list of selections on each loop.
  278.  
  279.   ii) csh:
  280.  
  281.   Although certain features aim to ease the withdrawal symptoms of csh
  282.   (ab)users, the syntax is in general rather different and you should
  283.   certainly not try to run scripts without modification.  The c2z script
  284.   is provided with the source (in scripts/c2z) to help convert .cshrc
  285.   and .login files; see also the next question concerning aliases,
  286.   particularly those with arguments.
  287.  
  288.   Csh-compatibility additions include:
  289.     Logout, rehash, source, (un)limit built-in commands.
  290.     *rc file for interactive shells.
  291.     Directory stacks.
  292.     Cshjunkie*, ignoreeof options.
  293.     The nonomatch option.
  294.     >&, |& etc. redirection.
  295.     foreach ... loops; alternate syntax for other loops.
  296.     $PROMPT as well as $PS1, $status as well as $?, $#argv as well as $#, ....
  297.     Escape sequences via % for prompts.
  298.     Special array variables $PATH etc. are colon-separated, $path are arrays.
  299.     !-type history (which may be turned off via `setopt nobanghist').
  300.     Arrays have csh-like features (see i)).
  301.  
  302.   iii) tcsh:
  303.  
  304.   (The previous section applies too, of course.)  Certain features have
  305.   been borrowed from tcsh, including $watch, run-help, $savehist,
  306.   $histlit, periodic commands etc., extended prompts, sched and
  307.   which/where built-ins.  Programmable completion was inspired by, but
  308.   is entirely different to, tcsh's `complete'. (There is a perl script
  309.   called lete2ctl in the scripts directory of the source distribution to
  310.   convert `complete' to `compctl' statements.)  This list is not
  311.   definitive: some features have gone in the other direction.
  312.  
  313.   If you're missing the editor function run-fg-editor, try something
  314.   with bindkey -s (which binds a string to a keystroke), e.g.
  315.     bindkey -s '^z' '\eqfg %$EDITOR:t\n'
  316.   which pushes the current line onto the stack and tries to bring a job
  317.   with the basename of your editor into the foreground.  Bindkey -s
  318.   allows limitless possibilities along these lines.
  319.  
  320.   iv) bash:
  321.   
  322.   Zsh has almost all the features that bash has (and much more); in
  323.   addition it is about twice as fast, though this is less impressive
  324.   than it sounds.  With the new malloc by Sven Wischnowsky (only used if
  325.   you arranged for USE_ZSH_MALLOC to be defined in config.h when
  326.   compiling zsh), zsh uses about the same amount of heap memory as bash,
  327.   which was previously the biggest gripe.  The only feature I am aware
  328.   of that zsh doesn't have is setting a numerical value for ignoreeof
  329.   --- it's always 10 --- but of course I don't use bash :-).
  330.  
  331.   However, zsh has no claims towards Posix compliancy and will not use
  332.   GNU readline (zle is more powerful).  In fact, bash is intended more
  333.   as an enhanced sh than a ksh work-alike; it doesn't handle [[ ... ]],
  334.   for example.
  335.  
  336.  
  337. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  338.  
  339.   First of all, check you are using the syntax
  340.     alias newcmd='list of commands'
  341.   and not
  342.     alias newcmd 'list of commands'
  343.   which won't work. (It tells you if `newcmd' and `list of commands' are
  344.   already defined as aliases.)
  345.  
  346.   Otherwise, your aliases probably contain references to the command
  347.   line of the form `\!*', etc.  Zsh does not handle this behaviour as it
  348.   has shell functions which provide a way of solving this problem more
  349.   consistent with other forms of argument handling.  For example, the
  350.   csh alias
  351.     alias cd 'cd \!*; echo $cwd'
  352.   can be replaced by the zsh function,
  353.     cd() { builtin cd $*; echo $PWD; }
  354.   (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop)
  355.   or, perhaps better,
  356.     cd() { builtin cd $*; print -D $PWD; }
  357.   (which converts your home directory to a ~).  In fact, this problem is
  358.   better solved by defining the special function chpwd() (see the manual).
  359.   Note also that the `;' at the end of the function is optional in zsh,
  360.   but not in ksh or sh (for sh's where it exists).
  361.  
  362.   Here is Bart Schaefer's guide to converting csh aliases for zsh.
  363.  
  364.     1.  If the csh alias references "parameters" (\!:1 \!* etc.),
  365.         then in zsh you need a function (referencing $1 $* etc.).
  366.         Otherwise, you can use a zsh alias.
  367.  
  368.     2.  If you use a zsh function, you need to refer _at_least_ to
  369.         $* in the body (inside the { }).  Parameters don't magically
  370.         appear inside the { } the way they get appended to an alias.
  371.     
  372.     3.  If the csh alias references its own name (alias rm "rm -i"),
  373.         then in a zsh function you need the "command" keyword
  374.         (function rm() { command rm -i $* }), but in a zsh alias
  375.         you don't (alias rm="rm -i").
  376.  
  377.     4.  If you have aliases that refer to each other (alias ls "ls -C";
  378.         alias lf "ls -F" ==> lf == ls -C -F) then you must either:
  379.         a.  convert all of them to zsh functions; or
  380.         b.  after converting, be sure your .zshrc defines all of your
  381.             aliases before it defines any of your functions.
  382.  
  383.     Those first four are all you really need, but here are four more for
  384.     heavy csh alias junkies:
  385.  
  386.     5.  Mapping from csh alias "parameter referencing" into zsh function
  387.         (assuming shwordsplit is NOT set in zsh):
  388.              csh                   zsh
  389.             =====               ==========
  390.             \!*                 $*              (or $argv)
  391.             \!^                 $1              (or $argv[1])
  392.             \!:1                $1
  393.             \!:2                $2              (or $argv[2], etc.)
  394.             \!$                 $*[$#]          (or $argv[$#], or $*[-1])
  395.             \!:1-4              $*[1,4]
  396.             \!:1-               $*[1,$#-1]      (or $*[1,-2])
  397.             \!^-                $*[1,$#-1]
  398.             \!*:q               "$@"            ($*:q doesn't work (yet))
  399.             \!*:x               $=*             ($*:x doesn't work (yet))
  400.  
  401.     6.  Remember that it is NOT a syntax error in a zsh function to
  402.         refer to a position ($1, $2, etc.) greater than the number of
  403.         parameters. (E.g., in a csh alias, a reference to \!:5 will
  404.         cause an error if 4 or fewer arguments are given; in a zsh
  405.     function, $5 is the empty string if there are 4 or fewer
  406.     parameters.)
  407.  
  408.     7.  To begin a zsh alias with a - (dash, hyphen) character, use
  409.         "alias --":
  410.                  csh                            zsh
  411.             ===============             ==================
  412.             alias - "fg %-"             alias -- -="fg %-"
  413.  
  414.     8.  Stay away from "alias -g" in zsh until you REALLY know what
  415.         you're doing.
  416.  
  417.   There is one other serious problem with aliases: consider
  418.         alias l='/bin/ls -F'
  419.         l() { /bin/ls -la $* | more }
  420.   `l' in the function definition is in command position and is expanded
  421.   as an alias, defining `/bin/ls' and `-F' as functions which call
  422.   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  423.   `function' to define a function, which doesn't expand aliases.  It is
  424.   possible to argue for extra warnings somewhere in this mess.  Luckily,
  425.   it is not possible to define `function' as an alias.
  426.  
  427.  
  428. 7) How do I turn off spelling correction for an individual command?
  429.  
  430.   You presumably have `setopt correctall' in an initialisation file, so
  431.   that zsh checks the spelling of each word in the command line.  You
  432.   probably do not want this behaviour for commands which do not operate
  433.   on existing files.
  434.   
  435.   The answer is to alias the offending command to itself with
  436.   `nocorrect' stuck on the front, e.g.
  437.        alias mkdir='nocorrect mkdir'
  438.  
  439.  
  440. 8) How do I get the meta key to work on my xterm?
  441.  
  442.   As stated in the manual, zsh needs to be told about the meta key by
  443.   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the command
  444.   line.  You probably also need to tell the terminal driver to allow the
  445.   `meta' bit of the character through; `stty pass8' is the usual
  446.   incantation.  Sample .zshrc entry:
  447.     [[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
  448.   or, on SYSVR4-ish systems without pass8,
  449.     [[ $TERM = "xterm" ]] && stty -parenb -istrip cs8 && bindkey -me
  450.   (disable parity detection, don't strip high bit, use 8-bit characters).
  451.   Make sure this comes *before* any bindkey entries in your .zshrc which
  452.   redefine keys normally defined in the emacs/vi keymap.
  453.  
  454.  
  455. 9) Why does my terminal act funny in way x?
  456.  
  457.   If you are using an OpenWindows cmdtool as your terminal, any
  458.   escape sequences (such as those produced by cursor keys) will be
  459.   swallowed up and never reach zsh.  Either use shelltool or avoid
  460.   commands with escape sequences.  You can also disable scrolling from
  461.   the cmdtool pane menu (which effectively turns it into a shelltool).
  462.   If you still want scrolling, try using an xterm with the scrollbar
  463.   activated.
  464.  
  465.   If that's not the problem, and you are using stty to change some tty
  466.   settings, make sure you haven't asked zsh to freeze the tty settings:
  467.   type
  468.     ttyctl -u
  469.   before any stty commands you use.
  470.  
  471.   On the other hand, if you aren't using stty and have problems you may
  472.   need the opposite:  `ttyctl -f' freezes the terminal to protect it
  473.   from hiccups introduced by other programmes (kermit has been known to
  474.   do this).
  475.  
  476.   If _that's_ not the problem, and you are having difficulties with
  477.   external commands (not part of zsh), and you think some terminal
  478.   setting is wrong (e.g. ^V is getting interpreted as `literal next
  479.   character' when you don't want it to be), try
  480.     ttyctl -u
  481.     STTY='lnext "^-"' commandname
  482.   (in this example), or just export STTY for all commands to see.  Note
  483.   that zsh doesn't reset the terminal completely afterwards: just the
  484.   modes it uses itself and a number of special processing characters
  485.   (see the stty(1) manual page).
  486.  
  487.   After the release of version 2.5, there is likely to be an overhaul
  488.   which allows the terminal modes used by the shell to be modified
  489.   separately from those seen by external programmes.  This is partially
  490.   implemented already:  in 2.5, the shell will be less susceptible to
  491.   mode changes inherited from programmes.
  492.  
  493.  
  494. 10) Why does `$var' where var="foo bar" not do what I expect?
  495.  
  496.   In most Bourne-shell derivatives, multi-word variables such as
  497.     var="foo bar"
  498.   are split into words when passed to a command or used in a `for foo in
  499.   $var' loop.  By default, zsh does not have that behaviour: the
  500.   variable remains intact.  (This is not a bug!  See below.)  An option
  501.   (shwordsplit) exists to provide compatibility.
  502.   
  503.   For example, defining the function args to show the number of its
  504.   arguments:
  505.     args() { echo $#; }
  506.   and with our definition of vble,
  507.     args $vble
  508.   produces the output `1'.  After
  509.     setopt shwordsplit
  510.   the same function produces the output `2', as with sh and ksh.
  511.   
  512.   Unless you need strict sh/ksh compatibility, you should ask yourself
  513.   whether you really want this behaviour, as it can produce unexpected
  514.   effects for variables with entirely innocuous embedded spaces.  The
  515.   natural way to produce word-splitting behaviour in zsh is via arrays.
  516.   For example,
  517.     set -A array one two three twenty
  518.   (or
  519.         array=(one two three twenty)
  520.   if you prefer), followed by
  521.     args $array
  522.   produces the output `4', regardless of the setting of shwordsplit.
  523.   Arrays are also much more versatile than single strings.
  524.  
  525.   Note also the "$@" method of word splitting is always available in zsh
  526.   functions and scripts (though strictly this does array splitting, not
  527.   word splitting), also the substitution ${=foo} to toggle word
  528.   splitting on variable `foo'.
  529.  
  530.   Shwordsplit is set when zsh is invoked with the name `ksh'.
  531.  
  532.  
  533. 11) My PATH, (MANPATH, ...) sometimes doesn't handle tildes.  What gives?
  534.  
  535.   The code has recently been overhauled, so take a look at the latest
  536.   version of 2.4beta.  This guarantees that no ~user expansion (or
  537.   =command expansion, which takes place at the same time) will happen if
  538.   the tilde is quoted, and also rationalises PATH-type variables by
  539.   expanding all unquoted assignments as if they are colon-separated
  540.   lists (so you may need to add or subtract a few extra quotes, but the
  541.   results are more predictable).  In addition typeset, etc., now should
  542.   behave like ordinary assignments in this respect; previously tildes in
  543.   typeset assignments were unquotable.
  544.  
  545.  
  546. 12) How does base arithmetic work?
  547.  
  548.   The syntax (e.g. using the `let' builtin is)
  549.     let 'foo = [16]ff'
  550.   (note this is different from ksh, which uses `16#ff'), or equivalently
  551.     (( foo = [16]ff ))
  552.   Then
  553.     echo $foo
  554.   gives the answer `255'.  It is possible to declare variables explicitly
  555.   to be integers, via
  556.     typeset -i foo
  557.   which has a different effect: namely the base used in the first
  558.   assignment (hexadecimal in the example) is subsequently used whenever
  559.   `foo' is displayed (although the internal representation is unchanged).
  560.   To ensure foo is always displayed in decimal, declare it as
  561.     typeset -i 10 foo
  562.   which requests base 10 for output.  You can change the output base of an
  563.   existing variable in this fashion.  Using the `$[ ... ]' method will
  564.   always display in decimal.
  565.  
  566.  
  567. 13) How do I get a newline in my prompt?
  568.  
  569.   You can place a literal newline in quotes, i.e.
  570.     PROMPT="Hi Joe,
  571.     what now?%# "
  572.   If you have the bad taste to set the option cshjunkiequotes, which
  573.   inhibits such behaviour, you will have to bracket this with 
  574.   `unsetopt cshjunkiequotes' and `setopt cshjunkiequotes', or put it in
  575.   your .zshrc before the option is set.
  576.   
  577.   Arguably the prompt code should handle `print'-like escapes.  Feel
  578.   free to write this :-).
  579.  
  580.  
  581. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  582.  
  583.   You probably have the extendedglob option set in which case ^ and #
  584.   are metacharacters.  ^a matches any file except one called a, so the
  585.   line is interpreted as bindkey followed by a list of files.  Quote the
  586.   ^ with a backslash or put quotation marks around ^a.
  587.  
  588.  
  589. 15) How do I execute command `foo' within function `foo'?
  590.  
  591.   The command `command foo' does just that.  You don't need this with
  592.   aliases, but you do with functions.  Note that error messages like
  593.         zsh: job table full or recursion limit exceeded
  594.   are a good sign that you tried calling `foo' in function `foo' without
  595.   using `command'.
  596.  
  597.  
  598. 16) Why can't I get zsh to work with SGI's `userenv'?
  599.  
  600.   It seems the Silicon Graphics `userenv' command interacts weirdly with
  601.   the line editor (zsh is not unique in this respect).  Add this line to
  602.   the top of your .zshenv file:
  603.         if [[ "${ENVONLY:-0}" -eq 1 ]]; then unsetopt zle; fi
  604.   --- which will turn the line editor off if it sees a `userenv' coming.
  605.   Don't turn zle back on with setopt until [[ $ENVONLY -ne 1 ]].
  606.  
  607.  
  608. 17) Why do history substitutions with single bangs do something funny?
  609.  
  610.   If you have a command like "echo !-2:$ !$", the first history
  611.   substitution then sets a default to which later history substitutions
  612.   with single unqualified bangs refer, so that !$ becomes equivalent to
  613.   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
  614.   to the last command.
  615.  
  616.  
  617. 18) Why does zsh kill off all my background jobs when I logout?
  618.  
  619.   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
  620.   you the option of having background jobs killed or not: the `nohup'
  621.   option exists if you don't want them killed.  Note that you can always
  622.   run programs with `nohup' in front of the pipeline whether or not the
  623.   option is set, which will prevent that job from being killed on
  624.   logout.  (Nohup is actually an external command.)
  625.  
  626.   The `disown' builtin is very useful in this respect: if zsh informs
  627.   you that you have background jobs when you try to logout, you can
  628.   `disown' all the ones you don't want killed when you exit.  This is
  629.   also a good way of making jobs you don't need the shell to know about
  630.   (such as commands which create new windows) invisible to the shell.
  631.  
  632.  
  633. 19) I don't have root access: how do I make zsh my login shell?
  634.  
  635.   Unfortunately, on many machines you can't use `chsh' to change your
  636.   shell unless the name of the shell is contained in /etc/shells, so if
  637.   you have your own copy of zsh you need some sleight-of-hand to use it
  638.   when you log on.  (Simply typing `zsh' is not really a solution since
  639.   you still have your original login shell waiting for when you exit.)
  640.   
  641.   The basic idea is to use `exec <zsh-path>' to replace the current
  642.   shell with zsh.  Often you can do this in a login file such as
  643.   .profile (if your shell is sh or ksh) or .login (if it's csh).  Make
  644.   sure you have some way of altering the file (e.g. via FTP) before you
  645.   try this as `exec' is often rather unforgiving.
  646.  
  647.   If you have zsh in a subdirectory `bin' of your home directory,
  648.   put this in .profile:
  649.     [ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
  650.   or if your login shell is csh or tcsh, put this in .login:
  651.     if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
  652.   (in each case the -l tells zsh it is a login shell).  
  653.  
  654.   It's not a good idea to put this (even without the -l) into .cshrc, at
  655.   least without some tests on what the csh is supposed to be doing, as
  656.   that will cause _every_ instance of csh to turn into a zsh and will
  657.   cause csh scripts (yes, unfortunately some people write these) which
  658.   do not call `csh -f' to fail.  If you want to tell xterm to run zsh,
  659.   change the SHELL environment variable to the full path of zsh at the
  660.   same time as you exec zsh.  If you have to exec zsh from your .cshrc,
  661.   a minimum safety check is `if ($?prompt) exec zsh'.
  662.  
  663.   If you like your login shell to appear in the process list as '-zsh',
  664.   you can link zsh to -zsh (e.g. by `ln -s ~/bin/zsh ~/bin/-zsh') and
  665.   change the exec to `exec -zsh'.  (Make sure -zsh is in your path.)
  666.   This has the same effect as the `-l' option.
  667.  
  668.   Footnote: if you DO have root access, make sure zsh goes in
  669.   /etc/shells on all appropriate machines, including NIS clients, or you
  670.   may have problems with FTP to that machine.
  671.  
  672.  
  673. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  674.  
  675.   People often ask why zsh has all these `unnecessary' csh-like features,
  676.   or alternatively why zsh doesn't understand more csh syntax.  This is
  677.   far from a definitive answer and the debate will no doubt continue.
  678.  
  679.   Paul's object in writing zsh was to produce a ksh-like shell which
  680.   would have features familiar to csh users.  For a long time, csh was
  681.   the preferred interactive shell and there is a strong resistance to
  682.   changing to something unfamiliar, hence the additional syntax and
  683.   csh_junkie options.  This argument still holds.  On the other hand,
  684.   the arguments for having what is close to a plug-in replacement for ksh
  685.   are, if anything, even more powerful:  the deficiencies of csh as a
  686.   programming language are well known (look in any Usenet FAQ archive, e.g.
  687.     rtfm.mit.edu:pub/usenet-by-group/news.answers/unix-faq/shell/csh-whynot
  688.   if you are in any doubt) and zsh is able to run many standard scripts
  689.   such as /etc/rc.
  690.   
  691.   Of course, this makes zsh rather large and quite messy so that it
  692.   seems to appeal mainly to hackers.  The only answer, perhaps not
  693.   entirely satisfactory, is that you have to ignore the bits you don't
  694.   want.
  695.  
  696.  
  697. 21) What bugs are currently known and unfixed?
  698.  
  699.   Here are some of the more well-known ones, very roughly in decreasing
  700.   order of significance.  Many of these can also be counted against
  701.   differences from ksh in question 5); note that this applies to the
  702.   latest beta version and that simple bugs are often fixed quite
  703.   quickly.  There is a file BUGS in the source distribution with more
  704.   detail.
  705.  
  706.   Pipelines ending in a while/until/for loop are uninterruptible.
  707.   Certain built-ins won't allow the `VAR=value command ...' assignment;
  708.     the ones that do don't unset VAR after use (may not really be a bug).
  709.     (N.B.: `exec foo=bar command' is a workaround for exec.)
  710.   The `histlit' option adds newlines to lines in the history
  711.     (and is broken in several other ways, e.g. !:x word selection;
  712.     it may be removed).
  713.   `time' is ignored with builtins and can't be used with {...} or (...);
  714.     in shells with no job control the command name is blank.
  715.   `set -x' (`setopt xtrace') doesn't show as much as it should.
  716.   The line number of errors inside control structures is always given
  717.     as the end of the structure (i.e. at `fi', `done', etc.).
  718.   $_ returns the last unexpanded word from the previous line (not command).
  719.   The :q modifier doesn't split words and -q and -x don't work for variables.
  720.   In vi mode, `u' can go past the original modification point.
  721.   Autocd won't use globbed filenames.
  722.   Linked directories can sometimes confuse zsh's idea of its cwd.
  723.   The singlelinezle option has problems with prompts containing escapes.
  724.   `wait' is not interruptible.
  725.   The =(..) substitution is not done synchronously.
  726.   trap '' INT does not work with interactive commands.
  727.   exec with a pipeline execs the first command and exits (sh does nothing).
  728.   $rprompt does not disappear when characters are entered fast.
  729.   (../)# does not stop at the root directory.
  730.   exec's in the tail of a list behave weirdly interactively.
  731.   read -q in a script assumes `n'.
  732.   Fd closure in a shell function stays around.
  733.  
  734.   Note that a few recent changes introduce incompatibilities (these are
  735.   not bugs): the -h option to compctl has been removed (use `-k hosts'
  736.   for the same effect); automatic handling of hosts after '@' has been
  737.   removed (use e.g. `compctl -u -x "n[-1,@]" -k hosts -- finger');
  738.   handling of backslashes in `echo' and `print' has changed; umask's
  739.   behaviour with respect to symbolic operators has reversed.
  740.  
  741.   There is at least one common bug which is not due to zsh.  If you have
  742.   abnormal behaviour with file descriptor 4, it's because your password
  743.   database is being read from the Network Information System and
  744.   getpwent() left this fd open.
  745.  
  746.  
  747. 22) Where do I report bugs, get more info / who's working on zsh?
  748.  
  749.   The shell is being maintained by various (entirely self-appointed)
  750.   subscribers to the mailing list,
  751.     zsh-list@sterling.com so any suggestions, complaints,
  752.   questions and matters for discussion should be sent there.  If you
  753.   want someone to mail you directly, say so.  Most patches to zsh appear
  754.   there first.
  755.   
  756.   A lower-volume list,
  757.     zsh-announce@sterling.com
  758.   exists for announcements of new features and proposed changes
  759.   requiring some decisions.
  760.  
  761.   Both lists are handled by an automated server.  The instructions for
  762.   zsh-announce are the same as for zsh-list: just change zsh-list to
  763.   zsh-announce everywhere in the following.
  764.  
  765.   To join zsh-list, send email to
  766.     Majordomo@sterling.com
  767.   containing
  768.     subscribe zsh-list <optional-address>
  769.   where <optional-address> can be blank if you want to subscribe from
  770.   your current email address.  Send the message `help' to the same
  771.   address for help on the list server; `unsubscribe zsh-list' also
  772.   works. (Don't send this to the list!) The list manager, Rick Ohnemus,
  773.   can be reached at
  774.     owner-zsh-list@sterling.com
  775.   (or `rick' at the same adress).
  776.  
  777.   The list (everything since May 1992) is archived in
  778.     ftp.sterling.com:zsh/zsh-list/YY-MM
  779.   where YY-MM are the year and month in digits.
  780.  
  781.   Of course, you can also post zsh queries to the Usenet group
  782.   comp.unix.shell; if all else fails, you could even e-mail me.
  783.  
  784.  
  785. 23) What's on the wish-list?
  786.  
  787.   Ksh/sh compatibility could be improved if required.  This would
  788.     be a useful long term goal.
  789.   Option for glob qualifiers to follow perl syntax.
  790.   Option to quote !-history lexically via '' but not "".
  791.   Binding of shell functions (or commands?) to key strokes --
  792.     requires some way of accessing the editing buffer from functions
  793.     and probably of executing zle functions as a command.
  794.   trap '...' FOO should be eval'd rather than called as a function.
  795.   `PATH=' should clear the PATH:  it inserts `.'; use `unset PATH' or
  796.     `path=()' for the time being.  This is not really a bug as the .
  797.     would be used internally in any case (cf. ksh).
  798.   Users should be able to create their own foopath/FOOPATH array/path
  799.     combinations.
  800.   The introduction to zsh (intro.*) could do with an update to reflect
  801.     extended completion (in particular) and other recent additions.
  802.  
  803.  
  804. Acknowledgments:
  805.  
  806. Thanks to zsh-list, in particular Bart Schaefer, for suggestions
  807. regarding this document; thanks to Jim Mattson and more recently Bas de
  808. Bakker for their hard work as archivists, and to Peter Gray for
  809. maintaining the mailing list, without which zsh might easily have died,
  810. and to the latest list maintainer, Rick Ohnemus.  The world is eternally
  811. in the debt of Paul Falstad for inventing zsh in the first place.
  812.  
  813.